package com.bookhouse.controller;

import com.bookhouse.entity.Category;
import com.bookhouse.service.CategoryService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by CiusCheung on 16/4/8.
 */

@Controller
@RequestMapping("/category")
public class CategoryController {

    @Resource(name = "categoryService")
    private CategoryService categoryService;

//    @RequestMapping("getCategoryList")
//    public String getAllSet(HttpServletRequest request){
//        Set<Category> sets = new HashSet<Category>();
//        Category categories = categoryService.get(Category.class,0);
//        Set<Category> levels1 = categories.getChildrenCategory();
//        for(Category level1 :levels1){
//            sets.add(level1);
//            level1.setSet(new HashSet<Category>());
//            Set<Category> levels2 = level1.getChildrenCategory();
//            for(Category level2 : levels2){
//                level1.getSet().add(level2);
//                level2.setSet(new HashSet<Category>());
//                Set<Category> levels3 = level2.getChildrenCategory();
//                for(Category level3 :levels3){
//                    level2.getSet().add(level3);
//                }
//            }
//            request.setAttribute("sets2",levels2);
//        }
//        request.setAttribute("sets1",sets);
//
//        request.setAttribute("sets3",levels1);
//        return "categoryMenu";
//    }
//
//    public String getParent(String categoryid,HttpServletRequest request){
//        Set<Category> sets = new HashSet<Category>();
//        Category category = categoryService.get(Category.class,Integer.parseInt(categoryid));
//        Category category1 = category.getParentCategory();
//        Category category2 = category1.getParentCategory();
//        category.setSet(new HashSet<Category>());
//        category1.setSet(new HashSet<Category>());
//        category1.getSet().add(category2);
//        category.getSet().add(category1);
//        sets.add(category);
//        request.setAttribute("categorySets1",sets);
//        request.setAttribute("categorySets2",category);
//        request.setAttribute("categorySets3",category1);
//        return "";
//    }



//    @RequestMapping("getCategoryList")
//    public String getAllSet(HttpServletRequest request){
//        return
//    }
}
